package com.itheima.controller;

import com.itheima.entity.Emp;
import com.itheima.entity.EmpQueryParam;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping("/emps")
    public Result page(EmpQueryParam param){
        PageBean page = empService.page(param);
        return Result.success(page);
    }
    @PostMapping("/emps")
    public Result save(@RequestBody Emp emp){
        empService.save(emp);
        return Result.success();
    }
    @DeleteMapping("/emps")
    public Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);
        return Result.success();
    }
    @GetMapping("/emps/{id}")
    public Result getById(@PathVariable Integer id){
        Emp emp=empService.getById(id);
        return Result.success(emp);
    }
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){
        empService.update(emp);
        return Result.success();
    }
}
